/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dados;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Observable;

/**
 *
 * @author rmb
 */
public class ListaMedicos extends Observable {
    
    private HashSet<Medico> listamed;

    public ListaMedicos() {
        listamed = new HashSet<Medico>();
    }
    public ListaMedicos(ListaMedicos list) {
        this.listamed = new HashSet<Medico>();
        
        for(Medico m : listamed) {
            this.listamed.add(m.clone());            
        }        
    }
    
    public HashSet<Medico> getList(){
        HashSet<Medico> aux = new HashSet<Medico>();
        
        for(Medico m : listamed) {
            aux.add(m.clone());
        }
        
        return aux;
    }
    
    public void add(Medico m) {        
        listamed.add(m);
        this.setChanged();
        this.notifyObservers("add");
    }
    
    public void remove(Medico m) {              
      
        Iterator<Medico> it = listamed.iterator();
        Medico med = null;
        boolean found = false;
        while(it.hasNext() && !found) {
            
            med = it.next();
            if(med.equals(m)){
                it.remove();
                found = true;
            }
        }
        
        
        this.setChanged();
        this.notifyObservers("remove");
    }
        
    

    
}
